<?php
function current_frontend() {
	global $INI;
	$a = array(
			'/login.php' => 'ログイン',
			'/reg.php' => '会員登録',
			'/stuffView.php' => 'スタッフ一覧',
			'/menueView.php' => 'メニュー一覧',
			'/campaign.php' => 'キャンペーン',
			'/shopInfo.php' => '店舗紹介'
			);
	
	$r = $_SERVER['REQUEST_URI'];
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			$l = $_k;
			break;
		}
    }
	return current_link($l, $a);
}

function current_backend($userId) {
	global $INI;
	$a_temp = array(
			'/service/index.php' => 'TOP',
			'/service/serviceTimeSearch.php' => 'ServiceTimeSearch',
			'/service/shopManage.php' => '１、ショップ設定',
			'/service/serviceManage.php' => '２、サービスと設備設定',
			'/service/staffManage.php' => '３、スタッフ管理',
			'/service/bookManage.php' => '４、予約状態確認',
			'/service/vipManage.php' => '５、会員統計',
			'/service/accountManage.php' => '６、管理権限',
			'/service/dataManage.php' => '７、会計統計'
	);
	$a = array();
	foreach($a_temp AS $_k=>$_v) {
		if( has_oauth($userId, $_k) ){
			$a[$_k] = $_v;
		}
    }
	
	$r = $_SERVER['REQUEST_URI'];
	if( preg_match('#deviceManage.php#', $r) ){
		$l = "/service/serviceManage.php";
	}
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			
			$l = $_k;
			break;
		}
    }
	
	
	return current_link($l, $a);
}

function bookmanage_backend($oathMap) {
	global $INI;
	$a = array();
	if( $oathMap[21] != null ){
		$a['/service/bookManage.php'] = '店の全体予約状態';
	}
	if( $oathMap[22] != null ){
		$a['/service/staffBookManage.php'] = 'スタッフ別予約状態';
	}
	if( $oathMap[23] != null ){
		$a['/service/bookDelList.php'] = '削除予約一覧';
	}
	$r = $_SERVER['REQUEST_URI'];
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			$l = $_k;
			break;
		}
    }
	
	
	return current_link($l, $a);
}

function servicemanage_backend($oathMap) {
	global $INI;
	$a = array();
	if( $oathMap[41] != null ){
		$a['/service/deviceManage.php'] = '設備管理';
	}
	if( $oathMap[42] != null ){
		$a['/service/serviceManage.php'] = 'サービス管理';
	}
	$r = $_SERVER['REQUEST_URI'];
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			$l = $_k;
			break;
		}
    }
	
	
	return current_link($l, $a);
}

function staffmanage_backend( $oathMap ) {
	global $INI;
	$a = array();
	if( $oathMap[31] != null ){
		$a['/service/staffManageEdit.php'] = 'staff 登録';
	}
	if( $oathMap[32] != null ){
		$a['/service/staffWorkTime.php'] = '勤務時間帯登録（スタッフ別）';
	}
	if( $oathMap[33] != null ){
		$a['/service/staffUnWorkTime.php'] = '臨時休み（スタッフ別）';
	}
	if( $oathMap[34] != null ){
		$a['/service/staffWorkList.php'] = 'スタッフ仕事一覧';
	}
	$r = $_SERVER['REQUEST_URI'];
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			$l = $_k;
			break;
		}
    }
	
	
	return current_link($l, $a);
}

function vipmanage_backend($oathMap){
	global $INI;
	$a = array();
	if( $oathMap[61] != null ){
		$a['/service/vipManage.php'] = '会員別予約回数統計';
	}
	/*if( $oathMap[62] != null ){
		$a['/service/vipStatus.php'] = '会員別予約状態';
	}*/
	if( $oathMap[63] != null ){
		$a['/service/vipList.php'] = '会員一覧';
	}
	$r = $_SERVER['REQUEST_URI'];
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			$l = $_k;
			break;
		}
    }
	
	
	return current_link($l, $a);
}

function accountmanage_backend($oathMap){
	global $INI;
	$a = array();
	if( $oathMap[71] != null ){
		$a['/service/accountManage.php'] = '管理権限登録';
	}
	if( $oathMap[72] != null ){
		$a['/service/adminRightList.php'] = '管理権限一覧';
	}
	if( $oathMap[73] != null ){
		$a['/service/mailSet.php'] = 'メール登録';
	}
	if( $oathMap[74] != null ){
		$a['/service/accessHistory.php'] = 'アクセス履歴';
	}
	$r = $_SERVER['REQUEST_URI'];
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			$l = $_k;
			break;
		}
    }
	
	
	return current_link($l, $a);
}

function datamanage_backend($oathMap){
	global $INI;
	$a = array();
	if( $oathMap[81] != null ){
		$a['/service/dataManage.php'] = 'スタッフ別（月勤務統計）';
	}
	if( $oathMap[82] != null ){
		$a['/service/dataManage_statistic.php'] = 'データ';
	}
	if( $oathMap[83] != null ){
		$a['/service/dailyReport.php'] = '日報管理';
	}
	$r = $_SERVER['REQUEST_URI'];
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			$l = $_k;
			break;
		}
    }
	
	
	return current_link($l, $a);
}


function current_link($link, $links, $span=false) {
	$html = '';
	$span = $span ? '<span></span>' : '';
	foreach($links AS $l=>$n) {
		if (trim($l,'/')==trim($link,'/')) {
			$html .= "<li class=\"current\"><a href=\"{$l}\">{$n}</a>{$span}</li>";
		}
		else $html .= "<li><a href=\"{$l}\">{$n}</a>{$span}</li>";
	}
	return $html;
}

function current_backend_new($userId) {
	global $INI;
	$a_temp = array(
			'/service/index.php' => 'TOP',
			'/service/serviceTimeSearch.php' => 'ServiceTimeSearch',
			'/service/shopManage.php' => '１、ショップ設定',
			'/service/serviceManage.php' => '２、サービスと設備設定',
			'/service/staffManage.php' => '３、スタッフ管理',
			'/service/bookManage.php' => '４、予約状態確認',
			'/service/vipManage.php' => '５、会員統計',
			'/service/accountManage.php' => '６、管理権限',
			'/service/dataManage.php' => '７、会計統計'
	);
	$a = array();
	foreach($a_temp AS $_k=>$_v) {
		if( has_oauth($userId, $_k) ){
			$a[$_k] = $_v;
		}
    }
	
	$r = $_SERVER['REQUEST_URI'];
	if( preg_match('#deviceManage.php#', $r) ){
		$l = "/service/serviceManage.php";
	}
	foreach($a AS $_k=>$_v) {
		if( preg_match('#'.$_k.'#', $r) ){
			
			$l = $_k;
			break;
		}
    }
	
	
	return current_link($l, $a);
}


function current_link_new($link, $links, $span=false) {
	$html = '';
	$span = $span ? '<span></span>' : '';
	foreach($links AS $l=>$n) {
		if (trim($l,'/')==trim($link,'/')) {
			$html .= "<li class=\"current\"><a href=\"{$l}\">{$n}</a>{$span}</li>";
		}
		else $html .= "<li><a href=\"{$l}\">{$n}</a>{$span}</li>";
	}
	return $html;
}

